#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
const int N=2e5+10;

ll a[N];
ll sum[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		priority_queue<ll> q1;
		priority_queue<ll> q2;
		int n,m;
		int ans=0;
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",a+i);
			sum[i]=sum[i-1]+a[i];
		}
		if(n==1)
		{
			cout<<0<<"\n";
			continue;
		}
		ll subsum=0;
		for(int i=m;i>1;i--)
		{
			subsum=subsum+a[i];
			if(a[i]>0)
			{
				q1.push(a[i]);
			}
			if(subsum>0)
			{
				ans++;
				subsum=subsum-2*q1.top();
				q1.pop();
			}
		}
		ll addsum=0;
		for(int i=m+1;i<=n;i++)
		{
			addsum+=a[i];
			if(a[i]<0)
			{
				q2.push(-a[i]);
			}
			if(addsum<0)
			{
				ans++;
				ll num=q2.top();
				addsum+=2*num;
				q2.pop();
			}
			
		}
		
		cout<<ans<<'\n';
	}

	return 0;
}

